home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / hexify.doc < prev    next >
Text File  |  1995-03-31  |  8KB  |  178 lines

  1. Item: 690 by alonzo at microsoft.UUCP 
  2. Author: Rick Grevelle 
  3.   Subj: Machine Code Version of Hexify 
  4.   Date: Mon Aug 13 1990 12:29  
  5.  
  6. [Note: This is an HP 28 program, not an HP 48 program!  It is included here 
  7. for study purposes only, since the 28 and the 48 are so similar... -jkh-] 
  8.  
  9. The following is a machine code version of HEXIFY.  It takes a string 
  10. of hexadecimal digits and converts them into an object. 
  11.  
  12. The code will also work on the HP48, with the minor modifications noted 
  13. in the comments (changing the value of two object prologs and CHEXIFY if 
  14. necessary). 
  15.  
  16. alonzo 
  17.  
  18. -------------------------------------------------------- 
  19. From: Rick Grevelle <uunet!tamuts.tamu.edu!n242df> 
  20. Newsgroups: comp.sys.handhelds 
  21. Subject: Machine Code Version of Hexify 
  22.  
  23. #00000: #143                        move.a   @d1,a     
  24. #00003: #132                        swap.a   a,d0      
  25. #00006: #100                        move.w            a,r0      
  26. #00009: #146                        move.a   @d0,c     
  27. #0000c: #06                         push.a   c         
  28. #0000e: #dd                         swap.a   b,c       
  29. #00010: #10a                        move.w            c,r2      
  30. #00013: #164                        add.a    #5,d0     
  31. #00016: #142                        move.a   @d0,a     
  32. #00019: #d6                         move.a   a,c       
  33. #0001b: #136                        swap.a   c,d0      
  34. #0001e: #164                        add.a    #5,d0     
  35. #00021: #c2                         add.a    a,c       
  36. #00023: #da                         move.a   c,a       
  37. #00025: #136                        swap.a   c,d0      
  38. #00028: #819f2                      srb.a    c         
  39. #0002d: #06                         push.a   c         
  40. #0002f: #137                        swap.a   c,d1      
  41. #00032: #109                        move.w            c,r1      
  42. #00035: #34e4a20                    move.p5           #02a4e,c          ; HP48: #02a2c 
  43. #0003c: #8a527                      brne.a   b,c,abort          
  44. #00041: #1c5                        sub.a    #6,d1     
  45. #00044: #4c6                        brcs     abort     
  46. #00047: #133                        swap.a   a,d1      
  47. #0004a: #dc                         swap.a   a,b       
  48. #0004c:                    loop:                       
  49. #0004c: #1c0                        sub.a    #1,d1     
  50. #0004f: #181                        sub.a    #2,d0     
  51. #00052: #14a                        move.b   @d0,a     
  52. #00055: #3114                       move.p2           #41,c     
  53. #00059: #9eed1                      brle.b   c,a,alpha          
  54. #0005e: #3103                       move.p2           #30,c     
  55. #00062: #b6a                        sub.b    c,a       
  56. #00065: #4b4                        brcs     abort     
  57. #00068: #3190                       move.p2           #09,c     
  58. #0006c: #9e624                      brlt.b   c,a,abort          
  59. #00071: #1510                       move.p   a,@d1     
  60. #00075: #6910                       jump.3   next 
  61. #00079:                    alpha:                      
  62. #00079: #b6a                        sub.b    c,a       
  63. #0007c: #3150                       move.p2           #05,c     
  64. #00080: #9e6e2                      brlt.b   c,a,abort          
  65. #00085: #30a                        move.p1           #a,c      
  66. #00088: #a0a                        add.p    c,a       
  67. #0008b: #1510                       move.p   a,@d1     
  68. #0008f:                    next: 
  69. #0008f: #cd                         dec.a    b         
  70. #00091: #5ab                        brcc     loop      
  71. #00094:                    result:                     
  72. #00094: #1c4                        sub.a    #5,d1     
  73. #00097: #07                         pop.a    c         
  74. #00099: #145                        move.a   c,@d1     
  75. #0009c: #1c4                        sub.a    #5,d1     
  76. #0009f: #07                         pop.a    c         
  77. #000a1: #145                        move.a   c,@d1     
  78. #000a4: #111                        move.w            r1,a      
  79. #000a7: #133                        swap.a   a,d1      
  80. #000aa: #141                        move.a   a,@d1     
  81. #000ad: #6900                       jump.3   exit      
  82. #000b1:                    abort:                      
  83. #000b1: #111                        move.w            r1,a      
  84. #000b4: #133                        swap.a   a,d1      
  85. #000b7:                    exit:                       
  86. #000b7: #112                        move.w            r2,a      
  87. #000ba: #dc                         swap.a   a,b       
  88. #000bc: #110                        move.w            r0,a      
  89. #000bf: #132                        swap.a   a,d0      
  90. #000c2: #142                        move.a   @d0,a     
  91. #000c5: #164                        add.a    #5,d0     
  92. #000c8: #808c                       jump.a   @a        
  93.  
  94. NOTE: I've included a program, CHEXIFY, which will create a  
  95.       version of HEXIFY that alleviates the above caveats.   
  96.  
  97. The following program works only on the HP 28S.  It creates a program on  
  98. the stack, which can then be stored in 'HEXIFY' and used to create any 
  99. further machine code programs. 
  100.  
  101. CHEXIFY[9BA9] 
  102. << 
  103.     <<  ""  +  A  >>  4 
  104.   # DD60641001231341h 
  105.   # 616316D241461A01h 
  106.   # 1602F918631AD2C4h 
  107.   # 25A802A4E4390173h 
  108.   # 10C1CD3316C45C17h  
  109.   # 131DEE94113A4118h 
  110.   # 26E909134B4A6B30h 
  111.   # 0513A6B019601514h 
  112.   # C0151A0AA032E6E9h 
  113.   # 04C1541704C1BA5Dh 
  114.   # 0961413311115417h 
  115.   # 1011CD2113311110h 
  116.   # C80846124123h 
  117. 48  STWS  #0h  OR  64  STWS 
  118. 1  12  START 
  119.   # 3B82h  SYSEVAL 
  120.       NEXT  
  121.   # 7195h  SYSEVAL 
  122.   # 44A4h  SYSEVAL 
  123.   # 7F77h  SYSEVAL 
  124.   # 3F41h  SYSEVAL 
  125.   # 3EEBh  SYSEVAL 
  126.                        >> 
  127.  
  128.  
  129. If you would rather have HEXIFY produce a CODE object every time instead of 
  130. requiring an object address argument then make these three changes: 
  131.           
  132.          Note: the addresses that appear before a colon, below, are for 
  133.               reference, and will change with these modifications.  They 
  134.                are not used except by the code itself. 
  135.  
  136. i)   Delete the instruction 
  137.          #0000c: #06                         push.a   c         
  138.  
  139. ii)  Replace the instruction  
  140.          #0009f: #07                         pop.a    c         
  141.      with  
  142.          #0009f: #3469C20                    move.p5  #02c96,c          ; HP48: #02dcc 
  143.  
  144. iii) Adjust the following branch addresses by 5 nibbles 
  145.  
  146.          #0003c: #8a527                      brne.a   b,c,abort          
  147.          #00044: #4c6                        brcs     abort     
  148.          #00065: #4b4                        brcs     abort     
  149.          #0006c: #9e624                      brlt.b   c,a,abort          
  150.          #00080: #9e6e2                      brlt.b   c,a,abort          
  151.      to 
  152.          #0003c: #8a577                      brne.a   b,c,abort          
  153.          #00044: #417                        brcs     abort     
  154.          #00065: #405                        brcs     abort     
  155.          #0006c: #9e674                      brlt.b   c,a,abort          
  156.          #00080: #9e633                      brlt.b   c,a,abort          
  157.  
  158. These changes have to be reflected in the data of the CHEXIFY program. 
  159. You can figure out where to make the modifications. 
  160.  
  161. Caveats 
  162. ------- 
  163. i)    If level 1 does not contain a string the program simply aborts. 
  164.  
  165. ii)   Each character is checked only as it is processed by the code 
  166.       loop.  If at any point the routine encounters invalid code, it  
  167.       aborts, leaving the unfinished result on the stack.  
  168.  
  169. iii)  Never use this routine on a copy of a string called to the stack 
  170.       that's stored in a variable without first making the stack copy 
  171.       unique. (i.e.  "" + ) 
  172.  
  173. iv)   Once the initial checking is complete, any errors will leave the 
  174.       string only partially converted. 
  175.  
  176. Rick Grevelle 
  177. uunet!tamuts.tamu.edu!n242df 
  178.